package bean.factorybean;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

/**
 * @Author com.alibaba.lizhen
 * @Date 2021/3/30 11:46 上午
 * @Version 1.0
 * @Description
 */
@Component("singletonPersonFactoryBean")
public class SingletonPersonFactoryBean implements FactoryBean<Person> {

	public SingletonPersonFactoryBean() {
		System.out.println("SingletonPersonFactoryBean --------");
	}

	private Person person;

	@Override
	public Person getObject() throws Exception {
		if(person == null){
			synchronized (SingletonPersonFactoryBean.class){
				if(person == null){
					return new Person("singletonPerson",11);
				}
			}
		}
		return person;
	}

	@Override
	public Class<?> getObjectType() {
		return Person.class;
	}



	@Override
	public boolean isSingleton() {
		return true;
	}
}
